package com.easyui.servlet;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.easyui.bean.Student;
import com.easyui.common.SelProject;
import com.easyui.common.SelStudent;

public class GetModifyServlet extends HttpServlet {
       
    public GetModifyServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
		

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		String msg = "";
		boolean success = true;
		
		HttpSession session = request.getSession(); //获的session
		String role = (String)session.getAttribute("role");
		String tno = (String)session.getAttribute("userID");
		
		if(role != null && role.trim().equals("teacher")) {//登录身份为老师
			if(tno != null && !tno.trim().equals("")) {//获取到该老师工号
				int pno = Integer.parseInt(request.getParameter("pno"));
System.out.println("pno:" + pno);
				String pname = request.getParameter("pname");
System.out.println("pname:" + pname);
				String []addtaker = request.getParameterValues("addtaker");
				String etime = request.getParameter("etime");
System.out.println("etime:" + etime);
				String pdetail = request.getParameter("pdetail");
System.out.println("pdetail:" + pdetail);
				String []stage = request.getParameterValues("stage");
System.out.println("stage:" + stage.length);
				
				success = new SelProject().modifyProject(tno, pno, pname, addtaker, etime, pdetail,stage);
				
			} else {//获得老师工号
				success = false;
			}
		} else {//是老师身份
			success = false;
		}
			
		if(success) {
			msg = "ok";
		} else {
			msg = "error";
		}
		
		out.print(msg);
		out.flush();
		out.close();
	}

}
